import code

from django.db import models
# 社区表动态


class Communitys(models.Model):
    title = models.CharField(max_length=20)
    # 直接保存图片储存爆炸，使用云端储存，mysql储存路径
    image1 = models.CharField(max_length=128, null=True)
    image2 = models.CharField(max_length=128, null=True)
    image3 = models.CharField(max_length=128, null=True)
    content = models.TextField(null=True)
    create_time = models.DateTimeField(auto_now_add=True)
    giveLike = models.IntegerField(default=0)
    # 外键，关联用户表，谁发布的
    user_id = models.ForeignKey('user_app.Users', on_delete=models.CASCADE, related_name='communitys_uid',default=None,unique=False)
    class Meta:
        db_table = 't_community'
    def __str__(self):
        return self.title
# 评论表
class Comments(models.Model):
    content = models.TextField()
    create_time = models.DateTimeField(null=True)
    # 外键，关联社区表，评论了哪个动态
    community = models.ForeignKey(Communitys,on_delete=models.CASCADE, related_name='comments_Com')
    # 外键，关联用户表，谁评论的
    user_id = models.ForeignKey('user_app.Users', on_delete=models.CASCADE, related_name='comments_uid',unique=False)

    class Meta:
        db_table = 't_comments'

class upvote(models.Model):
    community = models.ForeignKey('community_app.Communitys', on_delete=models.CASCADE, null=True,related_name='community_upvote_object')
    user_upvote = models.ForeignKey('user_app.Users',on_delete=models.CASCADE,null=True,unique=False,related_name='user_upvote_object')
    likeStatus = models.IntegerField(default=0, null=False)

    class Meta:
        db_table = "t_uplike"
        constraints = [
            models.UniqueConstraint(fields=['community', 'user_upvote'], name='unique_user_community')
        ]